/**
 * 
 */
package com.ar.myshares.services;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;

import com.ar.myshares.model.User;

/**
 * @author hernan.gastaud
 *
 */
@Service("userAssembler")
public class UserAssembler {

	public org.springframework.security.core.userdetails.User buildFromUserEntity(User userEntity) {
		String username = userEntity.getUsername();
		String password = userEntity.getPassword();
		boolean enable = userEntity.isLocked();
		boolean accountNotExpired = userEntity.isLocked();
		boolean credentialsNonExpired = userEntity.isLocked();
		boolean accountNotLocked = userEntity.isLocked();

		// Role
		Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
		authorities.add(new SimpleGrantedAuthority(userEntity.getRole().name()));
		return new org.springframework.security.core.userdetails.User(username, password, enable, accountNotExpired, credentialsNonExpired, accountNotLocked, authorities);
	}

}
